package edu.cicese.alz.swing;

import javax.swing.border.Border;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 9/08/12
 * Time: 03:57 PM
 */
public class DashedBorder implements Border {

	private static Insets EMPTY = new Insets(0, 0, 0, 0);

	@Override
	public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
		int vx, vy;

//		g.setColor(UIManager.getDefaults().getColor("Button.focus"));
		g.setColor(Color.GRAY);

		// draw upper and lower horizontal dashes
		for (vx = x; vx < (x + width); vx += 2) {
			g.fillRect(vx, y, 1, 1);
			g.fillRect(vx, y + height - 1, 1, 1);
		}

		// draw left and right vertical dashes
		for (vy = y; vy < (y + height); vy += 2) {
			g.fillRect(x, vy, 1, 1);
			g.fillRect(x + width - 1, vy, 1, 1);
		}
	}

	@Override
	public Insets getBorderInsets(Component c) {
		return EMPTY;
	}

	@Override
	public boolean isBorderOpaque() {
		return false;
	}
}